package fruit;

import java.math.BigDecimal;
import java.util.Objects;

public class Fruit {
    private final String name;
    private final BigDecimal pricePerKg;

    public Fruit(String name, BigDecimal pricePerKg) {
        this.name = name;
        this.pricePerKg = pricePerKg;
    }

    public BigDecimal calculateCost(int kilograms) {
        return pricePerKg.multiply(BigDecimal.valueOf(kilograms));
    }

    public String getName() {
        return name;
    }

    public BigDecimal getPricePerKg() {
        return pricePerKg;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Fruit)) return false;
        Fruit fruit = (Fruit) o;
        return Objects.equals(name, fruit.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    // 静态工厂方法
    public static Fruit apple() {
        return new Fruit("Apple", BigDecimal.valueOf(8));
    }

    public static Fruit strawberry() {
        return new Fruit("Strawberry", BigDecimal.valueOf(13));
    }

    public static Fruit mango() {
        return new Fruit("Mango", BigDecimal.valueOf(20));
    }
}